//
//  SJMeLogOutVC.m
//  SJPay
//
//  Created by 凯朱 on 2024/12/1.
//

#import "SJMeLogOutVC.h"

@interface SJMeLogOutVC ()
@property (nonatomic, strong)UIButton *logBtn;/*<#属性描述#>*/

@end

@implementation SJMeLogOutVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = kLocalString(@"设置");
    _logBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginStatusChange) name:@"loginStatusChange" object:nil];
    [_logBtn addTarget:self action:@selector(logAction) forControlEvents:UIControlEventTouchUpInside];
    _logBtn.frame = CGRectMake(20, 200, kScreenWidth-40, 50);
    [_logBtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
    _logBtn.titleLabel.font = kFontMedium(19);
    if (kIsTourst) {
        [_logBtn setTitle:kLocalString(@"点击登录") forState:UIControlStateNormal];
    }else{
        [_logBtn setTitle:kLocalString(@"退出登录") forState:UIControlStateNormal];
    }
    _logBtn.layer.cornerRadius = 25;
    _logBtn.layer.masksToBounds = YES;
    _logBtn.backgroundColor = kHexColor(@"6278FF");
    [self.view addSubview:_logBtn];

}

-(void)loginStatusChange{
    if (kIsTourst) {
        [_logBtn setTitle:kLocalString(@"点击登录") forState:UIControlStateNormal];
    }else{
        [_logBtn setTitle:kLocalString(@"退出登录") forState:UIControlStateNormal];
    }
}

-(void)logAction{
    if (kIsTourst) {
        [ZCTool pushToLoginVc];
    }else{
        [self AlertWithTitle:kLocalString(@"提示") message:kLocalString(@"确定退出登录吗？") andOthers:@[kLocalString(@"取消"),kLocalString(@"确定")] animated:NO action:^(NSInteger index) {
            [[UserManager sharedUserManager] removeUserData];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"loginStatusChange" object:nil];
            [self.navigationController popToRootViewControllerAnimated:YES];
            MainTabBarController *tab = [MainTabBarController new];
            [UIApplication sharedApplication].keyWindow.rootViewController = tab;
        }];
    }
}


@end
